package cst.a201sj.fraqmenttest201sj.fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;

import cst.a201sj.fraqmenttest201sj.R;
import cst.a201sj.fraqmenttest201sj.adapter.MyAdapter;
import cst.a201sj.fraqmenttest201sj.bean.ArticleBean;
import cst.a201sj.fraqmenttest201sj.iface.ArticleListener;
import cst.a201sj.fraqmenttest201sj.model.Activitymodel;


/**
 * A simple {@link Fragment} subclass.
 */
public class WeixinFragment extends Fragment implements ArticleListener {

    private View view;
    private Context context;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter mAdapter;
    List<ArticleBean>list=null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        context = getActivity();//获取当前文件
        view = inflater.inflate(R.layout.wfragment,container,false);

        //chushihua
        initRecyclerView();

        //从当前文件获取配件ID
        recyclerView = (RecyclerView) view.findViewById(R.id.recycleView);

        Activitymodel a = new Activitymodel();
        a.getLieBiaoList("article",2,"2ts2j910hv4m270hipde4a67d7",this);

       // Toast.makeText(context, "加载微信", Toast.LENGTH_SHORT).show();
        return view;
    }

    private void initRecyclerView() {
        recyclerView = (RecyclerView) view.findViewById(R.id.recycleView);
        //创建默认的线性LayoutManager
        layoutManager = new LinearLayoutManager(context);
        //设置布局管理器
        recyclerView.setLayoutManager(layoutManager);
        //如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
        recyclerView.setHasFixedSize(true);
        //创建并设置Adapter
        //list = getData();
        mAdapter = new MyAdapter(context);
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);
    }

    public void setLayoutManager(RecyclerView.LayoutManager layoutManager) {
        this.layoutManager = layoutManager;
    }

    @Override
    public void onResponse(List<ArticleBean> list) {
        this.list = list;
        mAdapter.setList(list);
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(context, "fail:NO", Toast.LENGTH_SHORT).show();
    }
}
